package com.example.service;

import com.example.entity.Information;
import com.example.mapper.InformationMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class InformationService {
    @Resource
    private InformationMapper informationMapper;

    public void add(Information information) {
        // 设置创建时间为当前日期
        information.setCreatTime(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        informationMapper.insert(information);
    }

    public PageInfo<Information> selectPage(Integer pageNum, Integer pageSize,Information information) {
        PageHelper.startPage(pageNum, pageSize);
        List<Information> list = informationMapper.selectAll(information);
        return PageInfo.of(list);
    }

    public void update(Information information) {
        informationMapper.updateById(information);
    }

    public void deleteById(Integer id) {
        informationMapper.deleteById(id);
    }
}
